package com.dolphin.common.component.var.enums;

import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

/**
 * @author shida
 */

@Getter
public enum RangePeriodTypeEnum {
    UNSET("未设置","NOTSET", 0, 0),
    HOUR("时","HOUR", 60 * 60 * 1000L, 1),
    DAY("日","DAY", 24 * 3600 * 1000L, 2),
    WEEK("周","WEEK", 7 * 24 * 3600 * 1000L, 3),
    MONTH("月","MONTH", 31 * 24 * 3600 * 1000L, 4)
    ;

    private String code;
    private String description;
    private Integer id;
    private long time;

    RangePeriodTypeEnum(String code, String description, long time, Integer id) {
        this.code = code;
        this.description = description;
        this.id = id;
        this.time = time;
    }

    public static RangePeriodTypeEnum fromString(String repeatPeriodType){
        if(StringUtils.isEmpty(repeatPeriodType)){
            return UNSET;
        }
        for (RangePeriodTypeEnum item : values()){
            if(item.name().equals(repeatPeriodType)){
                return item;
            }
        }

        throw new RuntimeException("Unsupported RangePeriodTypeEnum:" + repeatPeriodType);
    }
}
